import Vue from 'vue'
import Vuex from 'vuex'

const moduleFn = require.context('./modules', false, /\.js$/i)
const modules = moduleFn.keys().reduce((p, c) => {
  let key = c.match(/\.\/(\w+)\.js$/)[1]
  let value = { ...moduleFn(c).default, namespaced: true }
  p[key] = value
  return p
}, {})


Vue.use(Vuex)
const store = new Vuex.Store({
  modules
})

export default store